(function (f, define) {
    define(["./kendo.data"], f);
})(function () {

    (function () {

        (function ($) {
            var DataSource = kendo.data.DataSource,
                extend = $.extend,
                RestDataSource = DataSource.extend({
                    init: function (options) {
                        if (options.rest) {
                            var restOptions = extend({contentType: "application/json", dataType: "json"}, options.rest),
                                options = extend(true, {
                                    schema: {
                                        total: function (response) {
                                            return response.totalElements;
                                        },
                                        data: function (response) {
                                            return response.content;
                                        },
                                        groups: function (response) {
                                            return response.content;
                                        }
                                    },
                                    transport: {
                                        read: extend({type: "GET", traditional: true}, restOptions),
                                        create: extend({type: "POST"}, restOptions),
                                        update: extend({type: "POST"}, restOptions),
                                        destroy: extend({type: "DELETE"}, restOptions),
                                        parameterMap: function (options, operation) {
                                            if (operation !== "read" && options) {
                                                return kendo.stringify(options);
                                            } else if (options.sort) {
                                                options.sort = $.map(options.sort, function (item, index) {
                                                    return item.field + ',' + item.dir
                                                });
                                            }
                                            return options;
                                        }
                                    }
                                }, options);
                        }
                        DataSource.fn.init.call(this, options);
                    }
                });
            RestDataSource.create = function (options) {
                var dataSource = options || {};
                return dataSource instanceof DataSource ? dataSource :
                    new RestDataSource(options);
            };
            kendo.data.RestDataSource = RestDataSource;
        })(window.kendo.jQuery);

    })();

    return window.kendo;

}, typeof define == 'function' && define.amd ? define : function (_, f) {
    f();
});